package com.item.mall.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.item.mall.entity.Orders;
import com.item.mall.entity.User;
import com.item.mall.service.CartService;
import com.item.mall.service.OrderService;
import com.item.mall.service.UserAddressService;
import com.item.mall.vo.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张津瑞、彭家博
 * @since 2021-07-31
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    CartService cartService;
    @Autowired
    UserAddressService userAddressService;


    @GetMapping("/settlement3/{addressId}/{logistics}/{pay}/{cost}")
    public String settlement3(Orders orders,
                              @PathVariable("pay") String pay,
                              Model model,
                              HttpSession session){
        User user=(User) session.getAttribute("user");
        model.addAttribute("order",orderService.saveOrder(user.getId(),orders));
        model.addAttribute("pay",pay);
        return "forward:/orderDetail/add";
    }

    @GetMapping("/getOrderList")
    public ModelAndView getOrderList(HttpSession session){
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("orderList");
        modelAndView.addObject("orderList",orderService.getOrderVOList());
        User user =(User) session.getAttribute("user");
        modelAndView.addObject("cartList",cartService.getCartList(user.getId()));
        return modelAndView;
    }

}

